﻿/**
作者：常亮
时间：209-11-19
功能：实现用户显示
**/
var ArrList = new Array();
var PageSize = 18;
var page=1;
var indexpage;
var ArrList_R = new Array();
function ShowMain() {
    page = request("page")
    if (page == undefined||page=="") {
        page = 1;
        GetUserList(1);
    }
    else {
        page = request("page");
        GetUserList(page);
    }
}

//获取"信息列表"
function GetUserList(page) {
    indexpage = page;
    var url = encodeURI(SBasePath + '/action/UsersManage/UsersList.aspx');
    var pars = encodeURI("?PageIndex=" + page + "&PageSize=" + PageSize);
    var myAjax = new Ajax.Request(url, { method: 'get', parameters: pars, onComplete: sGetUserList, onFailure: fGetUserList });

}
//获取"信息列表"成功
function sGetUserList(o) {
    ArrList = MapAdmin_Userss(o);
    Total = MapPage(o, "RecordCount");
    PageIndex = MapPage(o, "PageIndex");
    PageTotal = Math.ceil(Total / PageSize)
    
    ShowContent();
}

function fGetUserList() { }

function GetUserListPage() {
    if (checkPage()) {
        var url = encodeURI(SBasePath + '/action/UsersManage/UsersList.aspx');
        var pars = encodeURI("?PageIndex=" + document.getElementById("page").value + "&PageSize=" + PageSize);
        var myAjax = new Ajax.Request(url, { method: 'get', parameters: pars, onComplete: sGetUserListPage, onFailure: fGetUserListPage });
    }
}

function sGetUserListPage(o) {
    ArrList = MapAdmin_Userss(o);
    Total = MapPage(o, "RecordCount");
    PageIndex = MapPage(o, "PageIndex");
    PageTotal = Math.ceil(Total / PageSize)
    if (document.getElementById("page").value > PageTotal) {
        MsgDlg('不能超出范围页数！');
        document.getElementById("page").value = "";
        return false;
    }
    ShowContent();
}

function fGetUserListPage() {

}

var checkPage = function() {
var page = document.getElementById("page").value;
    if (isNaN(page)||page=="") {
        MsgDlg('请输入页数！');
        return false;
    }
    return true;
}
//确认删除
function Del(UsersID) {
    if (UsersID == "ChkAllValue") {
        var idstr = SelectIDs(UsersID);
        if (idstr.length == 0) {
            MsgDlg(GetMsg("10"));
        }
        else {
            ConfrimDlg(GetMsg("2"), "DelUsers('" + idstr + "')");
        }
    } else {
        ConfrimDlg(GetMsg("2"), "DelUsers('" + UsersID + "')");
    }
}
var DelUsers = function(UsersID)//删除
{
    
        var url = encodeURI(SBasePath + '/action/UsersManage/DelUsers.aspx');
        var pars = encodeURI('?idstr=' + UsersID);
        var myAjax = new Ajax.Request(url, { method: 'get', parameters: pars, onComplete: sDelUsers, onFailure: fDelUsers });

};

//操作成功
function sDelUsers(o) {
    var root = o.responseXML.documentElement;
    var flag = GetXmlData(root, "Value");
    if (flag == "true") {
        MsgDlgLocal("删除成功！");
    }
    else {
        MsgDlg(GetMsg("0"));
    }
}

//操作失败
function fDelUsers(o) {
}

//增加用户
function UsersAdd() {
    location.href = SBasePath + "/htm/UsersManage/UsersAdd.htm";
}
//全选
function SelectAll(id, name)
{
    var checks = document.getElementsByTagName("input");
    for (var i = 0; i < checks.length; i++) {
        if (checks[i].name == name) {
 
            checks[i].checked = document.getElementById(id).checked;
        }
    }
};

function SelectIDs(name) {
    var checks = document.getElementsByTagName("input");
    var str = "";
    for (var i = 0; i < checks.length; i++) {
        if (checks[i].name == name && checks[i].checked) {
            str += checks[i].value + ",";
        }
    }
    return str;
};

function Edit(id) {
    window.top.frames["Content"].location.href = SBasePath + "/htm/UsersManage/UsersEdit.htm?Userid="+id+"&page="+indexpage;
}
function ShowContent() { 
 var str="";
 
 str+='<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">'
 str+='        <tr>';
 str+='            <td height="30">';
 str+='                <table width="100%" border="0" cellspacing="0" cellpadding="0">';
 str+='                    <tr>';
 str += '                        <td width="15" height="30" background="../../img/tab_03.gif">';
 str+='                          </td>';
 str+='                        <td  background="../../img/tab_05.gif">';
 str+='                            <img src="../../img/311.gif" width="16" height="16" />';
 str+='                            <span class="title1">用户列表</span>';
 str+='                        </td>';
 str+='                        <td  background="../../img/tab_05.gif">';
 str+='                            <table border="0" align="right" cellpadding="0" cellspacing="0">';
 str+='                                <tr>';
 str+='                                    <td width="60">';
 str+='                                        <table width="87%" border="0" cellpadding="0" cellspacing="0">';
 str+='                                            <tr>';
 str+='                                                <td>';
 str+='                                                    <div align="center">';
 str += '                                                        <input id="ChkAll" type="checkbox" onclick=\'SelectAll("ChkAll","ChkAllValue")\' />';
 str+='                                                    </div>';
 str+='                                                </td>';
 str+='                                                <td>';
 str+='                                                    <div align="center" class="f_green">全选</div>';
 str+='                                                </td>';
 str+='                                            </tr>';
 str+='                                        </table>';
 str += '                                    </td>';


 str += '                                    <td width="52">';
 str += '                                        <table width="88%" border="0" cellpadding="0" cellspacing="0">';
 str += '                                            <tr>';
 str += '                                                <td>';
 str += '                                                    <div align="center">';
 str += '                                                        <img src="../../img/311.gif" width="14" height="14" /></div>';
 str += '                                                </td>';
 str += '                                                <td>';
 str += '                                                    <div align="center" class="f_green"> <a href="javascript:ShenHe(\'ChkAllValue\')">通过</a></div>';
 str += '                                                </td>';
 str += '                                            </tr>';
 str += '                                        </table>';
 str += '                                    </td>';
 
 str+='                                    <td width="60">';
 str+='                                        <table width="90%" border="0" cellpadding="0" cellspacing="0">';
 str+='                                            <tr>';
 str+='                                                <td>';
 str+='                                                    <div align="center">';
 str+='                                                        <img src="../../img/001.gif" width="14" height="14" /></div>';
 str+='                                                </td>';
 str+='                                                <td>';
 str += '                                                    <div align="center" class="f_green"><a href="javascript:UsersAdd()">新增</a></div>';
 str+='                                                </td>';
 str+='                                            </tr>';
 str+='                                        </table>';
 str+='                                    </td>';
 str+='                                    <td width="52">';
 str+='                                        <table width="88%" border="0" cellpadding="0" cellspacing="0">';
 str+='                                            <tr>';
 str+='                                                <td>';
 str+='                                                    <div align="center">';
 str+='                                                        <img src="../../img/083.gif" width="14" height="14" /></div>';
 str+='                                                </td>';
 str+='                                                <td>';
 str += '                                                    <div align="center" class="f_green"> <a href="javascript:Del(\'ChkAllValue\')">删除</a></div>'; 
 str+='                                                </td>';
 str+='                                            </tr>';
 str+='                                        </table>';
 str+='                                    </td>';
 str+='                                </tr>';
 str+='                            </table>';
 str+='                        </td>';
 str += '                        <td width="14" background="../../img/tab_07.gif">';
 str+='                        </td>';
 str+='                    </tr>';
 str+='                </table>';
 str+='            </td>';
 str+='        </tr>';
 str+='        <tr>';
 str+='            <td>';
 str+='                <table width="100%" border="0" cellspacing="0" cellpadding="0">';
 str+='                    <tr>';
 str+='                        <td width="9" background="../../img/tab_12.gif"> &nbsp;</td>';
 str+='                        <td bgcolor="#f3ffe3">';
 str+='                            <table width="99%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#c0de98">';
 str+='                                <tr>';
 str+='                                    <td width="4%" height="26" background="../../img/tab_14.gif">';
 str+='                                        <div align="center" class="f_green">选择</div> ';                               
 str+='                                    </td>';
 str+='                                    <td width="4%" height="18" background="../../img/tab_14.gif">';
 str+='                                        <div align="center" class="f_green">序号</div>';
 str+='                                    </td>';
 str+='                                    <td height="18" width="6%" background="../../img/tab_14.gif">';
 str+='                                        <div align="center" class="f_green">用户名</div>';
 str+='                                    </td>';
 str+='                                    <td width="8%" height="18" background="../../img/tab_14.gif">';
 str+='                                        <div align="center" class="f_green">真实姓名</div>';
 str+='                                    </td>';
 str+='                                    <td width="14%" height="18" background="../../img/tab_14.gif">';
 str+='                                        <div align="center" class="f_green">登陆IP</div>';
 str+='                                    </td>';
 str+='                                    <td width="12%" height="18" background="../../img/tab_14.gif">';
 str+='                                        <div align="center" class="f_green">登陆时间</div>';
 str+='                                    </td>';
 str+='                                    <td width="5%" height="18" background="../../img/tab_14.gif">';
 str+='                                        <div align="center" class="f_green">登陆次数</div>';
 str += '                                    </td>';
//新加
// str += '                                    <td width="7%" height="18" background="../../img/tab_14.gif">';
// str += '                                        <div align="center" class="f_green">审核权限</div>';
// str += '                                    </td>';
// str += '                                    <td width="7%" height="18" background="../../img/tab_14.gif">';
// str += '                                        <div align="center" class="f_green">设置权限</div>';
// str += '                                    </td>';


 str += '                                    <td width="8%" height="18" background="../../img/tab_14.gif">';
 str += '                                        <div align="center" class="f_green">角色名称</div>';
 str += '                                    </td>';
 str += '                                    <td width="7%" height="18" background="../../img/tab_14.gif">';
 str+='                                        <div align="center" class="f_green">编辑</div>';
 str+='                                    </td>';
 str+='                                    <td width="8%" height="18" background="../../img/tab_14.gif">';
 str+='                                        <div align="center" class="f_green">删除</div>';
 str+='                                    </td>';
 str += '                                </tr>';

 for (var i = 0; i < ArrList.length; i++) {
     str += '                                <tr class="bg_w" onmouseout="this.className=\'bg_w\'" onmouseover="this.className=\'bg_g\'">';
     str += '                                    <td height="20">';
     str += '                                        <div align="center">';
     str += '                                            <input name="ChkAllValue" type="checkbox" class="" value="' + ArrList[i].UserID + '"/>';
     str += '                                        </div>';
     str += '                                    </td>';
     str += '                                    <td height="18" class="content"><div align="center">' + (i + 1) + '</div></td>';
     str += '                                    <td height="18" class="content"><div align="center">' + ArrList[i].UserName + '</div></td>';
     str += '                                    <td height="18" class="content"><div align="center">' + ArrList[i].DisplayName + '</div></td>';
     str += '                                    <td height="18" class="content"><div align="center">' + ArrList[i].LastLoginIP + '</div></td>';
     str += '                                    <td height="18" class="content"><div align="center">'+ ArrList[i].LastLoginDate + '</div></td>';
     str += '                                    <td height="18" class="content"><div align="center">' + ArrList[i].LoginAccout + '</div></td>';

     //新加
//     if (ArrList[i].SetShenHe == 1) {
//         str += '                                    <td height="18" class="content"><div align="center">通过</div></td>';
//     }
//     else {
//         str += '                                    <td height="18" class="content"><div align="center"><font color="Red">未通过</font></div></td>'; 
//     }
//     str += '                                    <td height="18" class="content"><div align="center"><a style="cursor: hand" onclick="javascript:ShenHe(\'' + ArrList[i].UserID + '\',\'' + ArrList[i].SetShenHe + '\')">设置</a></div></td>';
     
     str += '                                    <td height="18" class="content"><div align="center">';
     str += '                                        <a href="javascript:Show_xi(\'' + ArrList[i].DisplayName + '\',\'' + ArrList[i].RoleNames + '\',\'' + ArrList[i].UserID + '\')">' + ArrList[i].RoleNames + '</a>';
     str +='                                         </div></td>';
     str += '                                    <td height="18" class="content">';
     str += '                                      <div align="center">';
     str += '                                        <span><img src="../../img/037.gif" width="9" height="9" /></span><span> [</span><a href="javascript:Edit(\'' + ArrList[i].UserID + '\')">编辑</a><span>]</span></div>';
     str += '                                    </td>';
     str += '                                    <td height="18">';
     str += '                                      <div align="center">';
     str += '                                        <span><img src="../../img/010.gif" width="9" height="9" /></span><span> [</span><a href="javascript:Del(\'' + ArrList[i].UserID + '\')">删除</a><span>]</span></div>';
     str += '                                    </td>';
     str += '                                </tr>';
   }
     str += '                            </table>';
     str += '                        </td>';
     str += '                        <td width="9" background="../../img/tab_16.gif">&nbsp;</td>';
     str += '                    </tr>';
     str += '                </table>';
     str += '            </td>';
     str += '        </tr>';
 str+='        <tr>';
 str+='            <td height="29">';
 str+='                <table width="100%" border="0" cellspacing="0" cellpadding="0">';
 str+='                    <tr>';
 str+='                        <td width="15" height="29">';
 str+='                            <img src="../../img/tab_20.gif" width="15" height="29" />';
 str+='                        </td>';
 str+='                        <td background="../../img/tab_21.gif">';
 str+='                            <table width="100%" border="0" cellspacing="0" cellpadding="0">';
 str+='                                <tr>';
 str+='                                    <td width="25%" height="29" nowrap="nowrap">';
 str += '                                   <span class="f_green">共' + Total + '条记录, 当前第' + PageIndex + '/' + PageTotal + '页,每页' + PageSize + '条纪录</span>';
 str += '                                    </td>';
 str += '                                    <td width="75%" valign="top">';
 str += '                                        <div align="right">';
     if (PageTotal > 1) {
     str += '                                            <table width="352" height="20" border="0" cellpadding="0" cellspacing="0">';
     str += '                                                <tr>';
     str += '                                                    <td width="62" height="22" valign="middle">';
     str += '                                                        <div align="right">';
     str += '                                                          <a href="javascript:void(0)" onclick="FirstPage(\'GetUserList\')"><img src="../../img/first.gif" border="0" width="37" height="15" /></a></div>';
     str += '                                                    </td>';
     str += '                                                    <td width="50" height="22" valign="middle">';
     str += '                                                        <div align="right">';
     str += '                                                            <a href="javascript:void(0)" onclick="BackPage(\'GetUserList\')"><img src="../../img/back.gif" border="0" width="43" height="15" /></a></div>';
     str += '                                                    </td>';
     str += '                                                    <td width="54" height="22" valign="middle">';
     str += '                                                        <div align="right">';
     str += '                                                            <a href="javascript:void(0)" onclick="NextPage(\'GetUserList\')"><img src="../../img/next.gif" border="0" width="43" height="15" /></a></div>';
     str += '                                                    </td>';
     str += '                                                    <td width="49" height="22" valign="middle">';
     str += '                                                        <div align="right">';
     str += '                                                            <a href="javascript:void(0)" onclick="LastPage(\'GetUserList\')"><img src="../../img/last.gif" border="0" width="37" height="15" /></a></div>';
     str += '                                                    </td>';
     str += '                                                    <td width="59" height="22" valign="middle">';
     str += '                                                        <div align="right">';
     str += '                                                            转到第</div>';
     str += '                                                    </td>';
     str += '                                                    <td width="25" height="22" valign="middle">';
     str += '                                                        <input name="page" type="text" style="height: 12px; width: 25px;" size="5" />';
     str += '                                                    </td>';
     str += '                                                    <td width="23" height="22" valign="middle">页</td>';
     str += '                                                    <td width="30" height="22" valign="middle">';
     str += '                                                     <a href="javascript:void(0)" onclick="GetUserListPage()"><img src="../../img/go.gif" width="37" border="0" height="15" /></a>';
     str += '                                                    </td>';
     str+='                                                </tr>';
     str+='                                             </table>';
}
 str+='                                        </div>';
 str+='                                    </td>';
 str+='                                </tr>';
 str+='                            </table>';
 str+='                        </td>';
 str+='                        <td width="14">';
 str+='                            <img src="../../img/tab_22.gif" width="14" height="29" />';
 str+='                        </td>';
 str+='                    </tr>';
 str+='                </table>';
 str+='            </td>';
 str+='        </tr>';
 str += '    </table>';
 str += '    <div style="width: 100%; background-color:Gray; display:none; height: 100%; position:absolute;  left: 0; top: 0;" id="xie"></div><div style="width: 301px; display:none; height: 143px; position:absolute;  left: 100px; top: 127px;" id="content1"></div>';

 $("UsersList").innerHTML=str;
}

var a, b, c;
function Show_xi(disname, rolename, roleid) {
    a = disname;
    b = rolename;
    c = roleid;
    var url = encodeURI(SBasePath + '/action/RolesManage/RoleList.aspx');
    var pars = encodeURI("");
    var myAjax = new Ajax.Request(url, { method: 'get', parameters: pars, onComplete: sGetRoleList, onFailure: fGetRoleList });

}
//获取"信息列表"成功
function sGetRoleList(o) {
    ArrList_R = MapAdmin_Roles(o);

    Show_xi1();

}
function fGetRoleList() { }


//显示该角色信息
function Show_xi1(disname,rolename,roleid) {
    
    if (ArrList_R.length > 0) {
            var str1 = "";

            str1 += '<center><table border="0" style="cursor:move;"   cellpadding="0" cellspacing="1" bgcolor="#cccccc" id="move" style="position:absolute;" width="100%" height="70%">';
            str1 += '<tr style="cursor:move;" onmousedown="selectBegin(this);" onmousemove="selectMove(this);" onmouseup="selectEnd(this);"><td colspan="2" align="center" bgcolor="#f3ffe3"><b>用户角色修改</b></td></tr>';
            str1 += '<tr>';
            str1 += '<td width="30%" align="center" bgcolor="#f3ffe3">';
            str1 += '用户名';
            str1 += '</td>';
            str1 += '<td width="80%" align="left" bgcolor="#f3ffe3">';
            str1 += '<input id="id11" type="text" readonly="readonly" style="width:135px;" value="' + a + '"/>';
            str1 += '</td></tr>';
            str1 += '<tr><td width="30%" align="center" bgcolor="#f3ffe3">';
            str1 += '角色名称';
            str1 += '</td><td width="80%" align="left"  bgcolor="#f3ffe3">';
            str1 += '<input   id="name11" readonly="readonly" style="width:135px" type="text" value="'+b+'" />';
            str1 += '</td></tr>';
            str1 += '<tr><td width="30%" align="center" bgcolor="#f3ffe3">';
            str1 += '所属角色';
            str1 += '</td><td width="80%" align="left" bgcolor="#f3ffe3">';
            //选择用户的角色
            str1 += '     <div class="box"><div class="box2"><select id="juese">';
            var flag = 0;
            str1 += '<option value="0" selected="selected">请选择</option>';
            for (var i = 0; i < ArrList_R.length; i++) {
                str1 += '<option value="' + ArrList_R[i].RoleID + '"';
                if (ArrList_R[i].RoleName == b) { str1 += ' selected="selected"'; flag = 1; }
                str1 += '>';
                str1 += ArrList_R[i].RoleName;
                str1 += '</option>';
            }
            str1 += '</select></div></div>';
            str1 += '</td></tr>';
            str1 += '<tr><td width="100%" colspan="2" align="center" bgcolor="#f3ffe3">';
            str1 += '<input onclick="s_role(\''+c+'\')" type="button" class="Button01" value="保存"/>&nbsp;&nbsp;<input onclick="back()" type="button" class="Button01" value="取消"/>';
            str1 += '</td></tr></table></center>';

            $("xie").style.display = "block";
            $("xie").style.filter = "Alpha(Opacity=10)";
            $("content1").style.display = "block";
            $("content1").innerHTML = str1;
    }
}

//修改或添加的取消操作
function back() {
    $("xie").style.display = "none";
    $("content1").style.display = "none";
    $("content1").innerHTML = "";
}

function s_role(id) {

    var url = encodeURI(SBasePath + '/action/UsersManage/UserUpdateRole.aspx');
    var pars = encodeURI("userid=" + id + "&RoleID=" + juese.options[juese.selectedIndex].value + "&RoleName=" + juese.options[juese.selectedIndex].text);
    var myAjax = new Ajax.Request(url, { method: 'get', parameters: pars, onComplete: sGetRoleListupdate, onFailure: fGetRoleListupdate });

}
function sGetRoleListupdate(o) {
    var root = o.responseXML.documentElement;
    var Value = GetXmlData(root, "Value");

    if (Value == "true") {
        MsgDlgLocal('保存成功！');
    }

}
function fGetRoleListupdate() { 

}
///----------------------------------------------------------div拖拽事件-----------------------------------------------------onmousedown="selectBegin(this);" onmousemove="selectMove(this);" onmouseup="selectEnd(this);" 
var theFlag = 0; //操作是否开始(1是；0否)
var theDiv; //拖曳对象
var x = 0; //鼠标按下时的初始x座标
var y = 0; //鼠标按下时的初始y座标
var divTop = 0; //拖曳对象当前的top值
var divLeft = 0; //拖曳对象当前的left值

//鼠标按下事件
function selectBegin(e) {
    theFlag = 1;
    e.setCapture();

    theDiv = document.getElementById("move");
    //鼠标起始值
    x = parseInt(document.body.scrollLeft) + parseInt(event.clientX); //鼠标按下初始x座标值
    y = parseInt(document.body.scrollTop) + parseInt(event.clientY); //鼠标按下初始y座标值
    divTop = parseInt(theDiv.offsetTop); //拖曳对象当前的top值
    divLeft = parseInt(theDiv.offsetLeft); //拖曳对象当前的left值
}
//鼠标移动事件
function selectMove(e) {
    if (theFlag == 1) {
        var mouseX = parseInt(document.body.scrollLeft) + parseInt(event.clientX); //捕获鼠标当前座标
        var mouseY = parseInt(document.body.scrollTop) + parseInt(event.clientY);
        theDiv.style.top = divTop + (mouseY - y); //重置拖曳对象位置
        theDiv.style.left = divLeft + (mouseX - x);
    }
}
//鼠标松开事件
function selectEnd(e) {
    theFlag = 0;
    e.releaseCapture();
}
//-------------------------------------------------------------------------------------------------
//--------------------修改审核状态-------------------------------//
//确认
function ShenHe(UsersID, key) {
    if (UsersID == "ChkAllValue") {
        var idstr = SelectIDs(UsersID);
        if (idstr.length == 0) {
            MsgDlg("您还没有选择要审核的用户！");
        }
        else {
            ConfrimDlg("您确认要修改当前权限状态？", "shenheUsers('" + idstr + "')");
        }
    }
    else {
        ConfrimDlg("您确认要修改当前权限状态？", "shenheUser('" + UsersID + "','"+key+"')");
    }
}
var shenheUser = function(UsersID,key)//一个用户
{
    var url = encodeURI(SBasePath + '/action/UsersManage/ShenHe.aspx');
    var pars = encodeURI('?idstr=' + UsersID + "&key=" + key + "&page=" + indexpage);
    var myAjax = new Ajax.Request(url, { method: 'get', parameters: pars, onComplete: sshenheUsers, onFailure: fshenheUsers });
};
var shenheUsers = function(UsersID)//批量
{

    var url = encodeURI(SBasePath + '/action/UsersManage/ShenHe.aspx');
    var pars = encodeURI('?idstr=' + UsersID + "&key=all" + "&page=" + indexpage);
    var myAjax = new Ajax.Request(url, { method: 'get', parameters: pars, onComplete: sshenheUsers, onFailure: fshenheUsers });
};
//操作成功
function sshenheUsers(o) {
    var root = o.responseXML.documentElement;
    var flag = GetXmlData(root, "Value");
    if (flag == "true") {
        GetUserList(indexpage);
    }
    else {
        MsgDlg(GetMsg("0"));
    }
}
//操作失败
function fshenheUsers(o) {
}

